
class Generator{
	public:
		Generator(char *patt, char *toInc){
			this->pattern = patt;
			this->toIncrement = toInc;
			this->size = strlen(toInc);
		}

		void Next(){
			increaseString(toIncrement, size);
		}

		char* Get(){
			return toIncrement;
		}

	private:
		char *pattern;
		char *toIncrement;
		int size;		

		int nextCharacterByPattern(char* input){
			int elementsCount = strlen(pattern);
			int i;
			elementsCount--;
			int returnCode=-1;
	
			for(i=0; i<elementsCount; i++){
				if (pattern[i]==*input) {
					break;	
				}
			}
	
			if (i==elementsCount){
				i=0;
				returnCode=1; // rewind
				*input=pattern[i];
			}
			else{
				*input=pattern[i+1];
				returnCode=0;
			}
	
			return returnCode;
		}

		int increaseString(char input[], int isize){
			if (nextCharacterByPattern(&input[isize-1])==1){
				increaseString(input, isize-1);
			}
		}
};
